package net
{
	import flash3.framework.Map;
	
	import net.*;
	
	public class MessageGroup
	{
		protected static var _map:Map = new Map();
		protected static var _msgGroup:Map = new Map();
		public function MessageGroup():void
		{
		}
		public function addMessage(msgDef:MessageDef):void
		{
			var map:Map = getMessageGroup(msgDef._mainid);
			if(!map)
			{
				_map.put(msgDef._mainid, map=new Map());
			}
			map.put(msgDef._subid, msgDef);
			
		}
		
		public function getMessageGroup(mainid:uint):Map
		{
			if(!_map.containsKey(mainid))
				return null;
			return _map.getValue(mainid) as Map;
		}
		
		public function getMessageDef(mainid:uint, subid:uint):MessageDef
		{
			var map:Map = getMessageGroup(mainid);
			if(!map || !map.containsKey(subid)) 
				return null;
			return map.getValue(subid);
		}
		
		public function defMessage():void
		{
		}
		
		public function registerGroup():void
		{
			registerGroupByCls(LobbyLoginGroup);
			registerGroupByCls(ServerListGroup);
			registerGroupByCls(RoomLoginGroup);
			registerGroupByCls(ConfigGroup);
			registerGroupByCls(ManagerGroup);
			registerGroupByCls(RoomGroup);
			registerGroupByCls(SystemGroup);
			registerGroupByCls(TableGroup);
			registerGroupByCls(UserGroup);
			registerGroupByCls(CoreGroup);
			registerGroupByCls(FrameGroup);
			registerGroupByCls(GameGroup);
		}
		
		public function registerGroupByCls(cls:Class):void
		{
			var subClass:MessageGroup = new cls as MessageGroup;
			subClass.defMessage();
		}
		
		public function removeGroupByMainId(mainid:uint):void
		{
			if(!_map.containsKey(mainid))
				return;
			_map.remove(mainid);
		}
	}
}